package com.jacen.fzxs.service.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jacen.fzxs.dao.IBaseDao;
import com.jacen.fzxs.dao.IUserDao;
import com.jacen.fzxs.entity.UserEntity;
import com.jacen.fzxs.service.IUserService;
import com.jacen.fzxs.web.Pager;

/**
 * 用户Service
 * @author Jacen
 *
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class UserService extends BaseService<UserEntity> implements IUserService {
	
	@Resource
	private IUserDao userDao;
	
	@Override
	public IBaseDao<UserEntity> getDao() {
		// TODO Auto-generated method stub
		return userDao;
	}

	@Transactional(readOnly = true)
	public  List<UserEntity>  getPage(Pager pager ,Map<String, String> params) throws SQLException {
		pager.setTotalCount(getCount(params));
		return userDao.getPage((pager.getCurPageNum()-1) * pager.getPageSize() , pager.getPageSize(), params);
	}

	@Transactional(readOnly = true)
	public int getCount(Map<String, ? extends Object> params) throws SQLException {
		return userDao.getCount(params);
	}

	@Override
	@Transactional(readOnly = true)
	public List<UserEntity> getList(Map<String, String> params) {
		return userDao.getList(params);
	}

	@Override
	@Transactional(readOnly = true)
	public UserEntity login(String username, String password) {
		return userDao.login(username, password);
	}

	@Override
	public List<UserEntity> getListByRoleId(String roleId) throws Exception {
		return userDao.getListByRoleId(roleId);
	}

}
